home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
comm
/
msged400.zip
/
src
/
help.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-20
|
3KB
|
177 lines
/*
* HELP.C
*
* Written by John Dennis and released to the public domain.
*
* Help subsystem code.
*/
#include <stdio.h>
#include <string.h>
#include "help.h"
#include "msged.h"
#include "main.h"
#include "keys.h"
#include "memextra.h"
FILE *help;
HFileHdr Fheader;
HTopicHdr *topics;
char line[255];
int setup;
int CurrTopic;
static int numTopics;
void HelpInit(char *fileName)
{
int i;
setup = 0;
if ((help = fopen(fileName, "rb")) == NULL)
{
return;
}
fread(&Fheader, sizeof(HFileHdr), 1, help);
numTopics = (Fheader.topics[1] << 8) | Fheader.topics[0];
topics = xcalloc(numTopics, sizeof *topics);
for (i = 0; i < numTopics; i++)
{
fread(&topics[i], sizeof(HTopicHdr), 1, help);
}
setup = 1;
CurrTopic = 0;
}
void DisplayPage(long offset, int max)
{
char *s;
int done;
int line_num;
done = 0;
line_num = 0;
fseek(help, offset, SEEK_SET);
WClear(0, 0, 54, 14, cm[HP_NTXT]);
while (!done)
{
if (line_num == max)
break;
if (fgets(line, 254, help) == NULL)
break;
if (!strncmp(line, "*Page", 5) || !strncmp(line, "*End", 4))
break;
if (*line != '\n')
{
if ((s = strchr(line, '\n')) != NULL)
*s = '\0';
if (!strncmp(line, "*High", 5))
{
s = line + 5;
WWriteStr(0, line_num, cm[HP_TTXT], s);
}
else
WWriteStr(0, line_num, cm[HP_NTXT], line);
}
line_num++;
}
}
void DoHelp(int topic)
{
WND *hWnd, *hCurr;
long offset[20];
int depth;
int page;
int pages;
int ch;
int done;
if (help == NULL)
{
return;
}
if (topic < 0 || topic > numTopics)
{
return;
}
fseek(help, topics[topic].offset, SEEK_SET);
if (fgets(line, 254, help) == NULL)
return;
if (strncmp(line, "*Begin", 6))
return;
done = 0;
pages = 1;
offset[pages - 1] = ftell(help);
while (!done)
{
if (fgets(line, 254, help) == NULL)
{
return;
}
if (!strncmp(line, "*End", 4))
break;
if (!strncmp(line, "*Page", 5))
{
pages++;
offset[pages - 1] = ftell(help);
}
}
fseek(help, offset[0], SEEK_SET);
hCurr = Wtop();
hWnd = WPopUp(60, 18, INSBDR | SHADOW, cm[HP_BTXT], cm[HP_NTXT]);
WTitle(" Help ", cm[HP_TTXT]);
done = 0;
page = 0;
depth = 14;
DisplayPage(offset[page], depth);
while (!done)
{
ch = TTGetChr();
switch (ch)
{
case Key_PgDn:
if (page + 1 < pages)
{
page++;
DisplayPage(offset[page], depth);
}
break;
case Key_PgUp:
if (page > 0)
{
page--;
DisplayPage(offset[page], depth);
}
break;
case Key_Esc:
done = TRUE;
break;
default:
break;
}
}
WClose(hWnd);
WCurr(hCurr);
}